package com.toune.movie.mvp.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AutoCompleteTextView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.ScrollView;
import android.widget.TextView;

import com.toune.movie.R;
import com.toune.movie.base.BaseActivity;
import com.toune.movie.mvp.contract.LoginContract;
import com.toune.movie.mvp.presenter.LoginPresenter;
import com.toune.movie.vo.LoginVo;
import com.toune.movie.vo.VerifyVo;
import com.vondear.rxtool.view.RxToast;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by Administrator on 2018/4/26.
 */

public class LoginActivity extends BaseActivity<LoginPresenter> implements LoginContract.View {
    @BindView(R.id.login_progress)
    ProgressBar loginProgress;
    @BindView(R.id.email)
    AutoCompleteTextView email;
    @BindView(R.id.password)
    EditText password;
    @BindView(R.id.email_sign_in_button)
    Button emailSignInButton;
    @BindView(R.id.email_login_form)
    LinearLayout emailLoginForm;
    @BindView(R.id.login_form)
    ScrollView loginForm;
    @BindView(R.id.getVerifyTv)
    TextView getVerifyTv;

    @Override // 实例化presenter
    public LoginPresenter initPresenter() {
        return new LoginPresenter();
    }

    @Override
    public void loadMore() {

    }

    @Override
    public void refreData() {

    }

    @Override
    public void init(Bundle savedInstanceState) {

    }

    @Override
    protected int getLayout() {
        return R.layout.activity_login;
    }

    @Override
    protected String getTitleStr() {
        return null;
    }

    @Override
    protected void initEventAndData() {

    }

    @Override
    public void showError(String msg) {
        RxToast.showToast(msg);
    }

    @Override
    public void useNightMode(boolean isNight) {
        if (isNight) {
            RxToast.normal("到达第一步");
            startActivity(new Intent(LoginActivity.this,MainActivity.class));
        }
    }

    private VerifyVo verifyVo;

    @Override
    public void getVery(String phone) {
        mPresenter.getVery(phone);
    }

    @OnClick({R.id.getVerifyTv, R.id.email_sign_in_button})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.getVerifyTv:
                getVery(email.getText().toString());
                break;
            case R.id.email_sign_in_button:
//                if (verifyVo != null) {
//                    String code = verifyVo.getData()+"";
//                }
//                login(email.getText().toString(), password.getText().toString());

                startActivity(new Intent(LoginActivity.this,MainActivity.class));
                break;
        }
    }

    @Override
    public void login(String phone, String code) {
        mPresenter.login(phone, code);
    }

    @Override
    public void setVerify(VerifyVo verifyVo) {
        this.verifyVo = verifyVo;
        RxToast.info(String.valueOf(verifyVo.getData()));
    }

    @Override
    public void setLogin(LoginVo loginVo) {
    }
}
